package com.mj;

import com.mj.entity.Student;
import com.mj.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import javax.annotation.Resource;
import java.io.IOException;

public class Demo {
    protected SqlSessionFactory sf;
    protected SqlSession session;
    @Before
    public void init(){
        try {
            this.sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
            this.session = sf.openSession();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("库初始化");
    }
    @Test
    public void add(){
        StudentMapper sad = this.session.getMapper(StudentMapper.class);
        System.out.println(sad);
        int ins = sad.insert(new Student("花木兰",18,"从军部","100"));
        System.out.println(ins);
        System.out.println("运行不");
        this.session.commit();
    }
    @Test
    public void show(){
        System.out.println("程序");
    }
    @After
    public void close(){
        System.out.println("关闭");
    }
}
